<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$company = $db->getCell("select `name` from `companies` where `company_id` = '$cid' limit 1");
if (!$company)
	goToPage("/admin/votes");

loadPage("head.php");
?>
<h1>Список отзывов «<?php echo $company; ?>»</h1><br />
<table cellpadding='0' cellspacing='0' class='list'>
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='200px'>Пользователь</td>
		<td width='300px'>Отзыв</td>
		<td width='100px' class='actions'>Действия</td>
	</tr><?php
		$query = "select * from `votes`
			where `object_id` = '$cid' and `object_type` = 'company'
			order by `vote_id` desc";
		$votes = $db->getTable($query);
		foreach ($votes as $vote){
			echo "<tr>";
				echo "<td>$vote[vote_id]</td>";
				echo "<td>";
					echo "<span class='bold'>Имя:</span> $vote[nickname]<br />";
					echo "<span class='bold'>Email:</span> $vote[email]";
				echo "</td>";
				$likes = $db->getColumn("select `mean` from `likes` where `vote_id` = '$vote[vote_id]'");
				$helpful = $useless = 0;
				foreach ($likes as $like){
					if ($like == "helpful"){
						$helpful++;
					} elseif ($like == "useless"){
						$useless++;
					}
				}
				echo "<td>";
					echo "<span class='bold'>Оценка:</span> ".(
						$vote['mark'] == '1' ? "<span class='green'>Положительно</span>" : (
							$vote['mark'] == '-1' ? "<span class='fail'>Отрицательно</span>" : "<span class='gray'>Нейтрально</span>"
						)
					)."<br />";
					echo "<span class='bold'>Время:</span> ".date("d.m.Y H:i",$vote['time'])."<br />";
					echo "<span class='bold'>Полезен:</span> $helpful <span class='bold'>Бесполезен:</span> $useless<br />";
					echo "<span class='bold'>Текст:</span> $vote[text]";
				echo "</td>";
				echo "<td class='actions'><a href='/admin/c_votes/delete?c_id=$cid&v_id=$vote[vote_id]' class='delete'>удалить</a></td>";
			echo "</tr>";
		}
?></table>

<?php loadPage("footer.php"); ?>